package com.example.springbootresourcemodifiersample

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RestController


@RestController
@RequestMapping
class CarController {

    @Autowired
    lateinit var repository: CarJpaRepository

    /**
     * 获取到所有的car
     */
    @RequestMapping(value = arrayOf("getAllCar"), method = arrayOf(RequestMethod.GET))
    fun getAllCar():List<Car>{
        return repository.findAll()
    }

    /**
     * 添加一个Car
     */
    @RequestMapping(value = arrayOf("addCar"), method = arrayOf(RequestMethod.GET))
    fun addCar(name:String): Boolean {
        return repository.save(Car(name))!= null
    }


    @RequestMapping(value = arrayOf("unInterceptor"), method = arrayOf(RequestMethod.GET))
    fun unInterceptor():Boolean = true
}